﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using NewDDSys.Entity;
using NewDDSys.IBLL;
using NewDDSys.IDAL;
using NewDDSys.Factory;
using NewDDSys.Utility;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Web_UptZkcdt : System.Web.UI.Page
{
    private string dtnum = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        dtnum = Request.QueryString["Dtnum"];
        if (!IsPostBack)
        {
            btnUpt.Attributes.Add("onclick", "javascript:if(confirm('" + "确认无误，并修改么？" + "')== false) return false;");
            DataSet ds1 = BLLFactory.CreateZkcdtBLL().Select(dtnum);
            if (ds1 == null)
                Response.Write(" <script   language=javascript> window.alert( '无此记录，请联系管理员！ ');</script> ");
            else
            {
                string num = ds1.Tables[0].Rows[0]["num"].ToString();
                txtNUM.Text = dtnum;
                txtNUM.Attributes["contentEditable"] = "false";
                DataSet ds2 = BLLFactory.CreateKcBLL().Select(num);
                txtKu.Text = ds2.Tables[0].Rows[0]["ku"].ToString();
                txtKu.Attributes["contentEditable"] = "false";
                txtBanzu.Text = ds1.Tables[0].Rows[0]["banzu"].ToString();
                txtBanzu.Attributes["contentEditable"] = "false";
                txtTianbao.Text = ds1.Tables[0].Rows[0]["tianbao"].ToString();
                txtTianbao.Attributes["contentEditable"] = "false";
                txtPinzhong.Text = ds2.Tables[0].Rows[0]["pinzhong"].ToString();
                txtPinzhong.Attributes["contentEditable"] = "false";
                txtGuige.Text = ds2.Tables[0].Rows[0]["guige"].ToString();
                txtGuige.Attributes["contentEditable"] = "false";
                txtKN.Text = ds1.Tables[0].Rows[0]["kn"].ToString();
                txtKNWJ.Text = ds1.Tables[0].Rows[0]["knwj"].ToString();
                txtKNKL.Text = ds1.Tables[0].Rows[0]["knkl"].ToString();
                txtKNDC.Text = ds1.Tables[0].Rows[0]["kndc"].ToString();
                txtKNZY.Text = ds1.Tables[0].Rows[0]["knzy"].ToString();
                txtDK.Text = ds1.Tables[0].Rows[0]["dk"].ToString();
                txtDKWJ.Text = ds1.Tables[0].Rows[0]["dkwj"].ToString();
                txtDKKL.Text = ds1.Tables[0].Rows[0]["dkkl"].ToString();
                txtDKDC.Text = ds1.Tables[0].Rows[0]["dkdc"].ToString();
                txtDKZY.Text = ds1.Tables[0].Rows[0]["dkzy"].ToString();
            }

        }
    }
    protected void btnUpt_Click(object sender, EventArgs e)
    {
        if (txtKN.Text.ToString() != "" || txtDK.Text.ToString() != "")
        {
            decimal kn = Convert.ToDecimal(txtKN.Text.ToString());
            decimal knwj = Convert.ToDecimal(txtKNWJ.Text.ToString());
            decimal knkl = Convert.ToDecimal(txtKNKL.Text.ToString());
            decimal kndc = Convert.ToDecimal(txtKNDC.Text.ToString());
            decimal knzy = Convert.ToDecimal(txtKNZY.Text.ToString());
            decimal dk = Convert.ToDecimal(txtDK.Text.ToString());
            decimal dkwj = Convert.ToDecimal(txtDKWJ.Text.ToString());
            decimal dkkl = Convert.ToDecimal(txtDKKL.Text.ToString());
            decimal dkdc = Convert.ToDecimal(txtDKDC.Text.ToString());
            decimal dkzy = Convert.ToDecimal(txtDKZY.Text.ToString());
            if (kn < (knwj + knkl + kndc + knzy))
                Response.Write(" <script   language=javascript> window.alert( ' 库内、库内未缴库、库内可利用、库内短尺、库内自用材数量不正确！ ');</script> ");
            else if (dk < (dkwj + dkkl + dkdc + dkzy))
                Response.Write(" <script   language=javascript> window.alert( ' 东库、东库未缴库、东库可利用、东库短尺、东库自用材数量不正确！ ');</script> ");
            else
            {
                int f = BLLFactory.CreateZkcdtBLL().Update(dtnum, kn, kndc, knkl, knzy, knwj, dk, dkdc, dkkl, dkzy, dkwj);
                if (f >= 1)
                    Response.Write(" <script   language=javascript> window.alert( ' 修改成功！ ');</script> ");
            }
        }
        else
        {
            decimal knwj = Convert.ToDecimal(txtKNWJ.Text.ToString());
            decimal knkl = Convert.ToDecimal(txtKNKL.Text.ToString());
            decimal kndc = Convert.ToDecimal(txtKNDC.Text.ToString());
            decimal knzy = Convert.ToDecimal(txtKNZY.Text.ToString());
            decimal dkwj = Convert.ToDecimal(txtDKWJ.Text.ToString());
            decimal dkkl = Convert.ToDecimal(txtDKKL.Text.ToString());
            decimal dkdc = Convert.ToDecimal(txtDKDC.Text.ToString());
            decimal dkzy = Convert.ToDecimal(txtDKZY.Text.ToString());
            if (knwj != 0 || knkl != 0 || kndc != 0 || knzy != 0 || dkwj != 0 || dkkl != 0 || dkdc != 0 || dkzy != 0)
                Response.Write(" <script   language=javascript> window.alert( ' 库内未缴库、库内可利用、库内短尺、库内自用材、东库未缴库、东库可利用、东库短尺、东库自用材数量不正确！ ');</script> ");
            else
            {
                int f = BLLFactory.CreateZkcdtBLL().Update(dtnum, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
                if (f >= 1)
                    Response.Write(" <script   language=javascript> window.alert( ' 修改成功！ ');</script> ");
            }
        }


        Response.Redirect("ZKCDTJL.aspx");
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        int f = BLLFactory.CreateZkcdtBLL().Del(dtnum);
        if (f >= 1)
            Response.Write(" <script   language=javascript> window.alert( ' 删除成功！ ');</script> ");
        Response.Redirect("ZKCDTJL.aspx");
    }
}
